package com.devunion.reader.client.panel;

import com.devunion.reader.client.core.AbstractComposite;
import com.devunion.reader.client.to.AuthorTo;
import com.devunion.reader.client.to.PaperInfoTo;
import com.devunion.reader.client.widget.CustomLabelField;
import com.extjs.gxt.ui.client.Style;
import com.extjs.gxt.ui.client.binding.Bindings;
import com.extjs.gxt.ui.client.binding.FieldBinding;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.extjs.gxt.ui.client.widget.layout.RowData;

/**
 * @author Timoshenko Alexander 19.08.2009 : 18:07:44
 */
public class ProjectInfoPanel extends AbstractComposite {
    private Bindings authorBindings = new Bindings();
    private Bindings infoBindings = new Bindings();

    public void initialize() {        
        setLayout(new com.extjs.gxt.ui.client.widget.layout.RowLayout(Style.Orientation.VERTICAL));
        setScrollMode(Style.Scroll.AUTOY);
        setFrame(true);

        FieldSet authorInfo = new FieldSet();
        authorInfo.setHeading("Author");
        authorInfo.setLayout(new FormLayout(FormPanel.LabelAlign.TOP));

        CustomLabelField firstName = new CustomLabelField();
        firstName.setFieldLabel("First name");
        authorBindings.addFieldBinding(new FieldBinding(firstName, AuthorTo.FIRST_NAME));
        authorInfo.add(firstName, new FormData("90%"));

        CustomLabelField lastName = new CustomLabelField();
        lastName.setFieldLabel("Last name");
        authorBindings.addFieldBinding(new FieldBinding(lastName, AuthorTo.LAST_NAME));
        authorInfo.add(lastName, new FormData("90%"));

        FieldSet projectInfo = new FieldSet();
        projectInfo.setHeading("Project");
        projectInfo.setLayout(new FormLayout(FormPanel.LabelAlign.TOP));

        CustomLabelField titleField = new CustomLabelField();
        titleField.setFieldLabel("Title");
        infoBindings.addFieldBinding(new FieldBinding(titleField, PaperInfoTo.TITLE));
        projectInfo.add(titleField, new FormData("90%"));

        CustomLabelField typeField = new CustomLabelField();
        typeField.setFieldLabel("Type");
        infoBindings.addFieldBinding(new FieldBinding(typeField, PaperInfoTo.TYPE));
        projectInfo.add(typeField, new FormData("90%"));

        CustomLabelField languageField = new CustomLabelField();
        languageField.setFieldLabel("Language");
        infoBindings.addFieldBinding(new FieldBinding(languageField, PaperInfoTo.LANGUAGE));
        projectInfo.add(languageField, new FormData("90%"));

        CustomLabelField numberOfPagesField = new CustomLabelField();
        numberOfPagesField.setFieldLabel("Number of pages");
        infoBindings.addFieldBinding(new FieldBinding(numberOfPagesField, PaperInfoTo.NUMBER_OF_PAGES));
        projectInfo.add(numberOfPagesField, new FormData("90%"));

        CustomLabelField startDateField = new CustomLabelField();
        startDateField.setFieldLabel("Creation date");
        infoBindings.addFieldBinding(new FieldBinding(startDateField, PaperInfoTo.CREATION_START_DATE));
        projectInfo.add(startDateField, new FormData("90%"));

        CustomLabelField exactDateField = new CustomLabelField();
        exactDateField.setFieldLabel("Exact date");
        infoBindings.addFieldBinding(new FieldBinding(exactDateField, PaperInfoTo.CREATION_EXACT_DATE));
        projectInfo.add(exactDateField, new FormData("90%"));

        CustomLabelField endDateField = new CustomLabelField();
        endDateField.setFieldLabel("End date");
        infoBindings.addFieldBinding(new FieldBinding(endDateField, PaperInfoTo.CREATION_END_DATE));
        projectInfo.add(endDateField, new FormData("90%"));

        add(authorInfo, new RowData(1d,0.5d));
        add(projectInfo, new RowData(1d,1d));
    }

    public void bindAuthor(AuthorTo authorTo) {
        authorBindings.bind(authorTo);
    }

    public void bindInfo(PaperInfoTo paperInfoTo) {
        infoBindings.bind(paperInfoTo);
    }
}
